package com.whfc.iot.mach.codec;

import com.whfc.iot.mach.entity.MachMsg0x0C;
import com.whfc.iot.util.MsgDataCodecUtil;
import io.netty.buffer.ByteBuf;

import java.util.Date;

/**
 * @Description:
 * @author: xugcheng
 * @version: 1.0
 * @date: 2019/7/17 9:32
 */
public class MachMsgDataCodec0x0C implements MachMsgDataCodec<MachMsg0x0C> {

    @Override
    public void decode(ByteBuf buf, MachMsg0x0C msg) {
        Date time = MsgDataCodecUtil.readDateTime(buf);
        float accX = buf.readFloat();
        float accY = buf.readFloat();
        float accZ = buf.readFloat();
        float gyroX = buf.readFloat();
        float gyroY = buf.readFloat();
        float gyroZ = buf.readFloat();
        msg.setTime(time);
        msg.setAccX(accX);
        msg.setAccY(accY);
        msg.setAccZ(accZ);
        msg.setGyroX(gyroX);
        msg.setGyroY(gyroY);
        msg.setGyroZ(gyroZ);
    }

    @Override
    public void encode(ByteBuf buf, MachMsg0x0C msg) {
        Date time = msg.getTime();
        MsgDataCodecUtil.writeDateTime(buf, time);
        buf.writeFloat(msg.getAccX());
        buf.writeFloat(msg.getAccY());
        buf.writeFloat(msg.getAccZ());
        buf.writeFloat(msg.getGyroX());
        buf.writeFloat(msg.getGyroY());
        buf.writeFloat(msg.getGyroZ());
    }
}
